package com.fpc.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	
	/**
     * 判断时间是否在时间段内
     *
     * @param now  
     * @param begin
     * @param end
     * @return
     */
	public static boolean getBelongDate(LocalDate now,LocalDate begin,LocalDate end){
		if(now.equals(begin)||now.equals(end)) {
			   return true;
		}
        if(now.isAfter(begin) && now.isBefore(end)){
            return true;
        }else{
            return false;
        }
    }
	
    
    /**
     * 判断时间是否在时间段内
     *
     * @param nowTime
     * @param beginTime
     * @param endTime
     * @return
     */
    public static boolean belongCalendar(Date nowTime, Date beginTime,
            Date endTime) {
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);
 
        Calendar begin = Calendar.getInstance();
        begin.setTime(beginTime);
 
        Calendar end = Calendar.getInstance();
        end.setTime(endTime);
 
        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * String 转 LocalDateTime
     * @param dateTime  格式 必须是：2020-05-22 23:59:59   
     * @return
     */
    public static LocalDateTime strToLocalDateTime(String dateTime) {
    	  DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    	  LocalDateTime ldt = LocalDateTime.parse(dateTime,df);
    	  return  ldt;
    }
    /**
     * LocalDateTime 转  String
     * 
     */
    public static String strToLocalDateTime(LocalDateTime localDateTime) {
  	  DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  	  String localTime = df.format(localDateTime);
  	  return  localTime;
    }
  
    
  

	public static void main(String[] args) {
		LocalDate begin=strToLocalDateTime("2022-10-20 23:23:23").toLocalDate();
		System.out.println(begin);
		LocalDate end=strToLocalDateTime("2024-10-20 23:23:23").toLocalDate();
		System.out.println(end);
		LocalDate now=strToLocalDateTime("2023-10-20 23:23:23").toLocalDate();
		System.out.println(now);
		System.out.println(getBelongDate(now,begin, end));

	}

}
